<template>
  <div class="bg">
    <div class="wrap">
      <el-card class="box-card">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formLabelAlign"
          :rules="rules"
          ref="ruleForm"
        >
          <el-form-item label="用户名" prop="name">
            <el-input v-model="formLabelAlign.name"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="formLabelAlign.password"></el-input>
          </el-form-item>
          <el-form-item label="" >
            <el-button  type="primary" style="width:100%" @click="onsubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {
        name: "",
        password: "",
        type: "",
      },
      rules: {
          name: [
            { required: true, message: '请输入用户名！', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输密码', trigger: 'blur' }
          ],
         
        }
    };
  },
  methods:{
    onsubmit(){
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            console.log(this.formLabelAlign);
            this.$router.push('/')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
       
    }
  }
};
</script>

<style lang="less" scoped>
.bg {
  width: 100vw;
  height: 100vh;
  background: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;

  .wrap {
    width: 500px;
    // height: 500px;
  }
}
</style>